﻿using UnityEngine;
using System.Collections;
using FairyGUI;

/// <summary>
/// 创建房间界面
/// </summary>
public class UICreateRoomWindow : UIPopupWindow {

    static UICreateRoomWindow _inst = null;
    UICreateRoom_Games _gamesCtrl;
    UICreateRoom_Buttons _gameBtns;

    public UICreateRoomWindow()
    {
        // 加载界面
        UIPackage.AddPackage("UI/创建房间界面");
        base.Init(UIPackage.CreateObject("创建房间界面", "创建房间界面").asCom);

        GComponent createRComp = uiComp.GetChild("创建房间组件").asCom;

        // 初始化关闭按钮
        GButton closeBtn = createRComp.GetChild("返回按钮").asButton;
        closeBtn.onClick.Add(() => {
            _Close();
        });

        GComponent createComp = createRComp.GetChild("创建组件").asCom;

        // 初始化游戏资料
        _gamesCtrl = new UICreateRoom_Games(createComp.GetChild("游戏资料").asCom);

        // 初始化游戏按钮
        _gameBtns = new UICreateRoom_Buttons(createComp.GetChild("按钮组").asCom);
        _gameBtns.Init(_gamesCtrl);

        _inst = this;
    }

    void _Close()
    {
        DebugInfo.Log("关闭创建房间界面");

        AudioController.inst.PlayUIClickEffect();
        uiComp.RemoveFromParent();
        uiComp.Dispose();
        UIPackage.RemovePackage("UI/创建房间界面");
        base.Close();
    }

    /// <summary>
    /// 弹出窗口
    /// </summary>
    public static void Popup()
    {
        DebugInfo.Log("打开创建房间界面");
        UIRootController.inst.PopupWindow(new UICreateRoomWindow());
    }

    /// <summary>
    /// 关闭窗口
    /// </summary>
    public static void CloseWindow()
    {
        if (_inst != null)
        {
            _inst._Close();
            _inst = null;
        }
    }
}
